<?php
session_start();
require "lib/lib/GoogleChart.php";
require 'lib/lib/markers/GoogleChartShapeMarker.php';
require 'lib/lib/markers/GoogleChartTextMarker.php';
include_once("../../app/dao/database.php");
include "../../config/tanggal.php";

$tanggal = new Tanggal;

$class_db = new Database;

$class_db->connect->connect();

$query = "SELECT MONTH(corder.order_date) as month, corder.order_id as order_id, SUM(order_detail.total) as total 
        FROM corder INNER JOIN order_detail 
        ON corder.order_id = order_detail.order_id WHERE store=$_SESSION[id_toko] GROUP BY month ORDER BY order_id DESC LIMIT 0,7";

$hasil = $class_db->select_table($query);
//print_r($hasil);

$values = array();
$month = array();

foreach($hasil as $data){
    $values[] = $data['total'];
    
    $month[] = $data['month'];
}

//membalik values
$temp = array();

for($i=0;$i<count($values);$i++){
    $temp[] = 0;
}

$j=0;
for($i=count($values);$i>0;$i--){
    $temp[$i-1] = $values[$j];
    $j++;
}

//membalik bulan
$temp1 = array();

for($i=0;$i<count($month);$i++){
    $temp1[] = 0;
}

$j=0;
for($i=count($month);$i>0;$i--){
    $temp1[$i-1] = $month[$j];
    $j++;
}


/************/
$chart = new GoogleChart('bvs', 500, 300);

// manually forcing the scale to [0,100]
//$chart->setScale(0,100);

// add one line
$data = new GoogleChartData($temp);
$chart->addData($data);

// customize y axis
$y_axis = new GoogleChartAxis('y');
$y_axis->setDrawTickMarks(false)->setLabels(array()); //masih belom berhasil, seharusnya dihitung dulu max, kemudian range dibagi 5
$chart->addAxis($y_axis);

// customize x axis
$x_axis = new GoogleChartAxis('x');
//$x_axis->setTickMarks(5);
$x_axis->setDrawTickMarks(false)->setLabels($temp1);
$chart->addAxis($x_axis);

// add a shape marker with a border
$shape_marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE);
$shape_marker->setSize(6);
$shape_marker->setBorder(2);
$shape_marker->setData($data);
$chart->addMarker($shape_marker);

// add a value marker
$value_marker = new GoogleChartTextMarker(GoogleChartTextMarker::VALUE);
$value_marker->setData($data);
$chart->addMarker($value_marker);

header('Content-Type: image/png');
//echo $chart->toHtml();
echo $chart;